import { createStore, applyMiddleware } from 'redux'
import { finalReducer } from './reducers'
import thunk from 'redux-thunk'
//引入redux-devtools-extension(使用redux)
import {composeWithDevTools} from 'redux-devtools-extension'

import {persistStore, persistReducer} from 'redux-persist';
import storageSession from 'redux-persist/lib/storage/session'

const storageConfig = {
    key: 'root', 
    storage:storageSession, // 缓存机制
//blacklist: ['name','age'] // reducer 里不持久化的数据,除此外均为持久化数据
}
const myPersistReducer = persistReducer(storageConfig, finalReducer);
//生成store对象
const store = createStore(myPersistReducer,composeWithDevTools(applyMiddleware(thunk)));//内部会第一次调用reducer函数，得到初始state 
export const persistor = persistStore(store);
export default store